#include "other_process.h"


void on_before_command_line_processing_other(struct _cef_app_t *self, const cef_string_t *process_type,
                                                    struct _cef_command_line_t *command_line) {
    // 打印进程类型
    if (process_type) {
        cef_string_utf8_t cef_cmd_line_utf8 = {};
        cef_string_utf16_to_utf8(process_type->str, process_type->length, &cef_cmd_line_utf8);
        LOG_INFO("Process type: %s\n", cef_cmd_line_utf8.str);
        // cef_string_utf8_clear(&cef_cmd_line_utf8);
    } else {
        LOG_INFO("Process type: Browser\n");
    }

    // 修改命令行参数（完全禁用GPU）
    // const char *disable_switches[] = {
    //     "disable-gpu",
    //     "disable-software-rasterizer",
    //     "disable-gpu-compositing",
    //     "disable-gpu-early-init", // 新增：阻止早期初始化
    //     "disable-gpu-sandbox",    // 新增：解除沙盒限制
    //     "use-gl=disabled"         // 新增：强制禁用GL
    // };

    //  const char *disable_switches[] = {
    //     "disable-gpu"
    // };

    // for (int i = 0; i < sizeof(disable_switches) / sizeof(disable_switches[0]); i++) {
    //     cef_string_t switch_str = {};
    //     const char *switch_name = disable_switches[i];
    //     cef_string_utf8_to_utf16(switch_name, strlen(switch_name), &switch_str);
    //     command_line->append_switch(command_line, &switch_str);
    //     cef_string_clear(&switch_str);
    // }
}

other_app *other_app_create_t() {
    other_app *app = (other_app *) calloc(1, sizeof(other_app));
    app->cef_app.base.size = sizeof(cef_app_t);
    app->cef_app.on_before_command_line_processing = on_before_command_line_processing_other;

    return app;
}